<html>
<%@ include file="../../common/taglibs.jsp"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title><fmt:message key="format.message.system" /></title>
</head>

<body>
<script type="text/javascript">
Ext.namespace('azure', 'azure.common');
azure.common.memberList = function() {
	var cm_memberList,grid_memberList, store_memberList;
	var cm_BettingRecord,grid_BettingRecord, store_BettingRecord;
	var mainpanel;
	var toolbar_res;
	var addAccountWin,editAccountWin,addTradeWin;
	var grid_Account,store_Account,cm_Account;
	var addAccountForm,editAccountForm,addTradeForm;
	
	// 創建ColumnModel
	function createCM() {
		cm_memberList = new Ext.grid.ColumnModel([
			{header : '<fmt:message key="format.agent.loginName"/>',dataIndex : 'uname'},
			{header : '<fmt:message key="format.agent.userName"/>',dataIndex : 'trueName'},
			{header : '<fmt:message key="format.agent.phone"/>',dataIndex : 'tel'}, 
			{header : '<fmt:message key="format.content.Status"/>',dataIndex : 'status'},
			{header : '<fmt:message key="format.content.Operation"/>',width : 220,dataIndex : 'status',renderer : function(val, p, record) {
				var str;
				if(val == '冻结'){
					str = '<a href="#" onclick="javascript:disableMember(\'正常\');"}><fmt:message key="format.content.open" /></a>'
				}else{
					str = '<a href="#"} onclick="javascript:disableMember(\'冻结\');"><fmt:message key="format.content.close" /></a>'
				}
				return '<b><a href="#" onclick="javascript:account();"}><fmt:message key="format.member.transactions" /></a>&nbsp; '+
				'<a href="#" onclick="javascript:editMember();"}><fmt:message key="format.content.update" /></a>&nbsp; '+
				'<a href="#" onclick="javascript:delMemberList();"}><fmt:message key="format.content.delete" /></a>&nbsp; '+
				'<a href="#" onclick="javascript:bettingRecord();"}><fmt:message key="format.member.bettingRecord" /></a>&nbsp; '+str+'</b>';
			}}
		]);

		cm_Account = new Ext.grid.ColumnModel([
		   {header : '<fmt:message key="format.member.tradingHours"/>',dataIndex : 'tradeTime'},
		   {header : '<fmt:message key="format.member.score"/>',dataIndex : 'score'},
		   {header : '<fmt:message key="format.member.tradingType"/>',dataIndex : 'tradeType'},
		   {header : '<fmt:message key="format.member.balance"/>',dataIndex : 'amount'},
		   {header : '<fmt:message key="format.member.handlingpeople"/>',dataIndex : 'handler',}
		   ]);
		   
		cm_BettingRecord = new Ext.grid.ColumnModel([
		   {header : '<fmt:message key="format.history.Number"/>',dataIndex : 'periodNum'},
		   {header : '<fmt:message key="format.member.bettingTime"/>',dataIndex : 'betTime'},
		   {header : '<fmt:message key="format.member.orderNumber"/>',dataIndex : 'orderNum'},
		   {header : '<fmt:message key="format.member.content"/>',dataIndex : 'orderContent'},
		   {header : '<fmt:message key="format.member.Bets"/>',dataIndex : 'betMoney'},
		   {header : '<fmt:message key="format.member.Results"/>',dataIndex : 'betResult',}
		 ]);

	}

	function createStore() {
		store_memberList = new Ext.data.Store({
			proxy : new Ext.data.HttpProxy({
				url : 'Member_findByPage.action'
			}),
			reader : new Ext.data.JsonReader({
				root : 'pager.data',
				totalProperty : 'pager.totalSize'
			}, [{
				name : 'uname',
				mapping : 'uname'
			}, {
				name : 'trueName',
				mapping : 'trueName'
			}, {
				name : 'tel',
				mapping : 'tel'
			}, {
				name : 'status',
				mapping : 'status'
			}, {
				name : 'email',
				mapping : 'email'
			}, {
				name : 'uno',
				mapping : 'uno'
			}])
		});
		store_memberList.load({params:{start:0,limit:15}});
		
	store_Account = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : 'TradeRecord_findByPage.action'
		}),
		reader : new Ext.data.JsonReader({
			root : 'page.data',
			totalProperty : 'page.totalSize'
		}, [{
			name : 'tradeTime',
			mapping : 'tradeTime'
		},{
			name : 'score',
			mapping : 'score'
		},{
			name : 'tradeType',
			mapping : 'tradeType'
		},{
			name : 'amount',
			mapping : 'amount'
		},{
		name : 'handler',
		mapping : 'handler'
	}])
	});

	store_BettingRecord = new Ext.data.Store({
		proxy : new Ext.data.HttpProxy({
			url : 'Member_findHistoryBetByMemberId.action'
		}),
		reader : new Ext.data.JsonReader({
			root : 'pager.data',
			totalProperty : 'pager.totalSize'
		}, [
		{
			name : 'periodNum',
			mapping : 'periodNum'
		},{
			name : 'betTime',
			mapping : 'betTime'
		},{
			name : 'orderNum',
			mapping : 'orderNum'
		},{
			name : 'orderContent',
			mapping : 'orderContent'
		},{
			name : 'betMoney',
			mapping : 'betMoney'
		},{
			name : 'betResult',
			mapping : 'betResult'
		},{
			name : 'memberId',
			mapping : 'memberId'
		}
		])
	});
	}

	function createToolbar(){};
	function createGrid() {
		createCM();
		createStore();
		createToolbar();

		grid_memberList = new Ext.grid.GridPanel({
			cm : cm_memberList,
			store : store_memberList,
			tbar:[{text:'<fmt:message key="format.message.add"/>',handler:addMember}],
			bbar : new Ext.PagingToolbar({
				store : store_memberList,
				pageSize : 15,
				displayInfo : true,
				displayMsg : '<fmt:message key="format.paging.displayMsg"/>',
				emptyMsg : '<fmt:message key="format.paging.emptyMsg"/>'
			})
		});
		
		grid_Account = new Ext.grid.GridPanel({
			title:'<fmt:message key="format.member.ManagementAccount"/>',
			cm : cm_Account,
			store : store_Account,
			height :220,
			tbar:[{text:'<fmt:message key="format.member.result"/>',handler:results},{text:'<fmt:message key="format.member.withdraw"/>',handler:withdraw}],
			bbar : new Ext.PagingToolbar({
				store : store_Account,
				pageSize : 15,
				displayInfo : true,
				displayMsg : '<fmt:message key="format.paging.displayMsg"/>',
				emptyMsg : '<fmt:message key="format.paging.emptyMsg"/>'
		})

		});

		grid_BettingRecord = new Ext.grid.GridPanel({
			title:'<fmt:message key="format.member.bettingHistory"/>',
			cm : cm_BettingRecord,
			store : store_BettingRecord,
			height :220,
			tbar:['<fmt:message key="format.gameEntry.game"/>',
				 new Ext.form.TextField({
						fieldLabel : '<fmt:message key="format.gameEntry.game"/>',
						width : 220,
						id:'gameName',
						name : 'gameName'
					}),
			      '<fmt:message key="format.member.bettingDate"/>',
			      new Ext.form.DateField({
			  	    width:140,
			  	    name:'startTime',
			  	  	id:'startTime',
			  	 	format:'Y-m-d'  
			  		}),
			      '<fmt:message key="format.member.bettingand"/>',
			      new Ext.form.DateField({
			  	    width:140,
			  	    name:'endTime',
			  	  	id:'endTime',
			  	 	format:'Y-m-d'  
			  		}),{text:'<fmt:message key="format.history.query"/>',handler:queryBettingRecord}],
			bbar : new Ext.PagingToolbar({
				store : store_BettingRecord,
				pageSize : 15,
				displayInfo : true,
				displayMsg : '<fmt:message key="format.paging.displayMsg"/>',
				emptyMsg : '<fmt:message key="format.paging.emptyMsg"/>'
		})

		});
	}

	function createUI() {
		createGrid();
		createForm();
		grid_BettingRecord.hide();
		mainpanel = new Ext.Panel({
			frame : false,
			id:'playPanel',
			renderTo :'memberListDiv',
			layout:'fit',
			items : [grid_memberList, grid_Account,grid_BettingRecord]
		});
	}

	function createForm() {

		addAccountForm = new Ext.form.FormPanel({
			labelWidth : 65,
			frame : true,
			url:'Member_createNewMember.action',
			labelSeparator : ':',
			labelAlign : 'left',
			defaultType : 'textfield',
			items : [
			new Ext.form.Hidden({
				name : 'member.agent.uno',
				value:'${user.uno}'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.loginName"/>',
				width : 220,
				name : 'member.uname'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.message.pwd"/>',
				width : 220,
				name : 'member.upwd'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.userName"/>',
				width : 220,
				name : 'member.trueName'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.phone"/>',
				width : 220,
				name : 'member.contactInfo.tel'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.email"/>',
				width : 220,
				name : 'member.contactInfo.email'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.betSetting.minBet"/>',
				width : 220,
				name : 'member.minBet'
			}),									
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.betSetting.maxBet"/>',
				name : 'member.maxBet',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			}),									
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.member.amount"/>',
				name : 'member.account.amount',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			})]
		});

		editAccountForm = new Ext.form.FormPanel({
			labelWidth : 65,
			frame : true,
			url:'Member_updateMember.action',
			labelSeparator : ':',
			labelAlign : 'left',
			defaultType : 'textfield',
			items : [
			new Ext.form.Hidden({
				id:'uno',
				name : 'member.uno'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.loginName"/>',
				id:'uname',
				width : 220,
				name : 'member.uname'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.message.pwd"/>',
				id:'upwd',
				width : 220,
				name : 'member.upwd'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.userName"/>',
				id:'trueName',
				width : 220,
				name : 'member.trueName'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.phone"/>',
				id:'tel',
				width : 220,
				name : 'member.contactInfo.tel'
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.agent.email"/>',
				id:'email',
				width : 220,
				name : 'member.contactInfo.email'
			}),
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.betSetting.minBet"/>',
				width : 220,
				id:'minBet',
				name : 'member.minBet'
			}),												
			new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.betSetting.maxBet"/>',
				name : 'member.maxBet',
				id:'maxBet',
				width : 220,
				labelWidth : 50,
				anchor : '99%'
			})]
		});
	
		addTradeForm = new Ext.form.FormPanel({
			labelWidth : 65,
			frame : true,
			url:'TradeRecord_saveTrade.action',
			labelSeparator : ':',
			labelAlign : 'left',
			defaultType : 'textfield',
			items : [
			new Ext.form.Hidden({
				id:'unoNum',
				name : 'uno'
			}),new Ext.form.TextField({
				id:'uname',
				fieldLabel : '<fmt:message key="format.trade.uname"/>',
				width : 220
			}),new Ext.form.TextField({
				id:'amount',
				fieldLabel : '<fmt:message key="format.trade.amount"/>',
				width : 220
			}),new Ext.form.TextField({
				fieldLabel : '<fmt:message key="format.trade.score"/>',
				width : 220,
				name : 'score'
			})]
		});
	}
	
	addMember=function () {
		addAccountWin = new Ext.Window({
			width : 320,
			height : 350,
			closable : false,
			layout : 'fit',
			items : addAccountForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.message.confirm"/>',
				handler : createMember,
				formBind : true
			}, {
				text : '<fmt:message key="format.message.cancel"/>',
				handler : function() {
					addAccountWin.hide();
				}
			}]
		});
		addAccountWin.title = '<fmt:message key="format.title.bettingcell.add"/>';
		addAccountWin.show(Ext.getBody());
	}

	trade=function(tradeType){
		addTradeWin = new Ext.Window({
			width : 320,
			height : 300,
			closable : false,
			layout : 'fit',
			items : addTradeForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.message.confirm"/>',
				handler : function(btn){
					if(addTradeForm.getForm().isValid()){
						btn.disable();
						addTradeForm.getForm().submit({
							method : 'POST',
							waitMsg : '<fmt:message key="format.message.saving"/>',
							params : {
								'tradeType' : tradeType
							},
							successProperty : false,
							success : function() {
								Ext.Msg.alert('<fmt:message key="format.message.success"/>', 
								'<fmt:message key="format.message.save.success"/>',function() {
									btn.enable();
								});
							},
							failure : function() {
								Ext.Msg.alert('<fmt:message key="format.message.failure"/>', 
								'<fmt:message key="format.message.save.failure"/>');
								btn.enable();
							}
						});
						}
				},
				formBind : true
			}, {
				text : '<fmt:message key="format.message.cancel"/>',
				handler : function() {
					addTradeWin.hide();
				}
			}]
		});
		var rec = grid_memberList.getSelections()[0];
		if (rec != null) {
			Ext.Ajax.request({
				url: 'TradeRecord_toTrade.action',
				method : 'POST',
				params : {
					'uno' : rec.data.uno
				},
				success:function (response){
					addTradeWin.title = tradeType;
					addTradeWin.show(Ext.getBody());
					var dataSource = Ext.util.JSON.decode(response.responseText);
					document.getElementById("unoNum").value=dataSource.memberDto.uno;
					document.getElementById("uname").value=dataSource.memberDto.uname;
					document.getElementById("amount").value=dataSource.memberDto.amount;

				}
		 });
		} else {
			Ext.MessageBox.alert('<fmt:message key="format.content.Warning"/>',
				'<fmt:message key="format.content.aterror"/>');
		}

	}
	
	editMember=function () {
		editAccountWin = new Ext.Window({
			width : 320,
			height : 450,
			closable : false,
			layout : 'fit',
			items : editAccountForm,
			modal : true,
			tbar : [{
				text : '<fmt:message key="format.message.confirm"/>',
				handler : updateMember,
				formBind : true
			}, {
				text : '<fmt:message key="format.message.cancel"/>',
				handler : function() {
					editAccountWin.hide();
				}
			}]
		});
		var rec = grid_memberList.getSelections()[0];
		if (rec != null) {
			editAccountWin.title = '<fmt:message key="format.title.bettingcell.add"/>';
			editAccountWin.show(Ext.getBody());
			editAccountForm.getForm().loadRecord(rec);
		} else {
			Ext.MessageBox.alert('<fmt:message key="format.content.Warning"/>',
				'<fmt:message key="format.content.aterror"/>');
		}
	}	
	
	showLog = function(id,titles,gameName){
		grid_Account.setTitle(titles);
		store_Account.load({params:{start:0,limit:15,gameName:gameName}});
	}

	function createMember(btn){
		var rec = grid_memberList.getSelections()[0];
		if(addAccountForm.getForm().isValid()){
			btn.disable();
			addAccountForm.getForm().submit({
				method : 'POST',
				waitMsg : '<fmt:message key="format.message.saving"/>',
				successProperty : false,
				success : function() {
					Ext.Msg.alert('<fmt:message key="format.message.success"/>', 
					'<fmt:message key="format.message.save.success"/>',function() {
						btn.enable();
						store_memberList.reload();
					});
				},
				failure : function() {
					Ext.Msg.alert('<fmt:message key="format.message.failure"/>', 
					'<fmt:message key="format.message.save.failure"/>');
					btn.enable();
				}
			});
			}

	}

	function updateMember(btn){
		var rec = grid_memberList.getSelections()[0];
		var rec1 = grid_memberList.getSelections()[0];
		if(editAccountForm.getForm().isValid()){
			btn.disable();
			editAccountForm.getForm().submit({
				method : 'POST',
				waitMsg : '<fmt:message key="format.message.saving"/>',
				successProperty : false,
				params : {
					'member.id' : rec1.data.id,
					'member.memberList.id':rec.data.id
				},
				success : function() {
					Ext.Msg.alert('<fmt:message key="format.message.success"/>', 
					'<fmt:message key="format.message.update.success"/>',function() {
						btn.enable();
						store_memberList.reload();
					});
				},
				failure : function() {
					Ext.Msg.alert('<fmt:message key="format.message.failure"/>', 
					'<fmt:message key="format.message.update.failure"/>');
					btn.enable();
				}
			});
			}
	}
	disableMember = function (status){
		var rec = grid_memberList.getSelections()[0];
		Ext.MessageBox.wait('<fmt:message key="format.content.wait"/>');
		Ext.Ajax.request( {
			url : 'Member_updateMemberStatus.action',
			method : 'POST',
			params : {
				'member.uno' : rec.data.uno,
				'member.status':status
			},
			success : function(response) {
				grid_memberList.getStore().reload();
				Ext.MessageBox.hide();
			},
			failure : function() {
				Ext.Msg.show( {
					title : '<fmt:message key="format.content.errortitle"/>',
					msg : '<fmt:message key="format.content.errormsg"/>',
					buttons : Ext.Msg.OK,
					icon : Ext.Msg.ERROR
				});
			}
		});
		
	}
	delMemberList =function (){
		var dict = grid_memberList.getSelections()[0];
		if (dict != null) {
			Ext.MessageBox.confirm('<fmt:message key="format.message.delete"/>', '<fmt:message key="format.content.isdelete"/>', delMember)
		} else {
			Ext.MessageBox.alert('<fmt:message key="format.message.prompt"/>', '<fmt:message key="format.message.selectData"/>');
		}
	}

	function delMember(d){
		if (d == 'yes') {
			var r = grid_memberList.getSelectionModel().getSelected();
			var rec = grid_memberList.getSelections()[0];
			Ext.MessageBox.wait('<fmt:message key="format.content.wait"/>');
			Ext.Ajax.request( {
				url : 'Member_deleteMember.action',
				params : {
					'member.uno' : rec.data.uno
				},
				success : function(response) {
					grid_memberList.getStore().remove(rec);
					Ext.MessageBox.hide();
				},
				failure : function() {
					Ext.Msg.show( {
						title : '<fmt:message key="format.content.errortitle"/>',
						msg : '<fmt:message key="format.content.errormsg"/>',
						buttons : Ext.Msg.OK,
						icon : Ext.Msg.ERROR
					});
				}
			});
		}
	}

	function queryBettingRecord(){
		var rec = grid_memberList.getSelections()[0];
		var gameName=document.getElementById("gameName").value
		var startTime=document.getElementById("startTime").value
		var endTime=document.getElementById("endTime").value
		store_BettingRecord.load({params:{start:0,limit:15,'member.uno':rec.data.uno,gameName:gameName,startTime:startTime,endTime:endTime}});
	}
	
	account=function(){
		grid_BettingRecord.hide();
		grid_Account.show();
		var rec = grid_memberList.getSelections()[0];
		grid_Account.setTitle(rec.data.uname+"-->"+'<fmt:message key="format.member.ManagementAccount"/>');
		store_Account.load({params:{start:0,limit:15,uno:rec.data.uno}});
	}

	bettingRecord=function(){
		grid_Account.hide();
		grid_BettingRecord.show();
		var rec = grid_memberList.getSelections()[0];
		grid_BettingRecord.setTitle(rec.data.uname+"-->"+'<fmt:message key="format.member.bettingHistory"/>');
		store_BettingRecord.load({params:{start:0,limit:15}});
	}

	function results(){
		trade("充值");
	}
	function withdraw(){
		trade("提现");
	}
	return {
		init : function() {
			createUI();
		}
	};

}();
Ext.onReady(azure.common.memberList.init, azure.common.memberList, true);
</script>

<div id="memberListDiv"></div>
</body>
</html>
